package com.warm.orm.utils;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil;
import com.warm.orm.domain.BaseEntity;

import java.util.Date;

public class DateParaUtils {

    public static Date getStartDate(BaseEntity entity) {
        return getDate(entity, "beginTime");
    }

    private static Date getDate(BaseEntity entity, String key) {
        Object datePara = entity.getParams().get(key);
        if (ObjUtil.isEmpty(datePara)) {
            return null;
        }

        return DateUtil.parseDate(DateUtil.formatDate(Convert.toDate(datePara)));
    }

    public static Date getEndDate(BaseEntity entity) {
        return getDate(entity, "endTime");
    }
}
